﻿using System;
using System.Collections;
using Spring.Data.NHibernate.Support;

using Project.Model.Rights;
using Project.Repository.Rights;
using NHibernate;
using System.Collections.Generic;
using Project.Model;
using Project.Repository;

namespace Project.Repository.Rights
{
    public class UserDao : Repository<User>, IUserDao
    {
		//public User GetByName(string name)
		//{
		//    //string hql = string.Format("From User obj Where obj.Name = '{0}'", name);
		//    string hql = "From User obj Where obj.Name = '" + name + "'";

		//    IQuery query = this.Session.CreateQuery(hql);

		//    IList<User> list = this.Session.CreateCriteria(hql).List<User>();

		//    if (list != null && list.Count == 1)
		//    {
		//        return list[0];
		//    }
		//    else
		//    {
		//        return null;
		//    }
		//}

		public IList<User> GetAll(User searchModel)
		{
			string hql = "From User obj  ";
			if (!string.IsNullOrEmpty(searchModel.Name))
				hql += " Where obj.Name = '" + searchModel.Name + "'";
			if (searchModel.Version > 0)
				hql += " Where obj.Version = '" + searchModel.Version + "'";

			IQuery query = this.Session.CreateQuery(hql);

			return query.List<User>();
		}




	}
}
